import { getPlaylist } from "../../api/detail"
import { getRanking } from "../../api/home"

// pages/song-menu-detail/song-menu-detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: '推荐歌曲',
    // typeName: '',
    songInfo: {},
    type: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.setData({
    //   title: options.ranking === "全部" ? "热门歌单" : options.ranking,
    //   typeName: options.ranking
    // })
    this.getSongs(options.id)
    this.setData({type: options.type})
  },

  // 获取榜单歌曲
  async getSongs(id) {
    if(id) {
      getPlaylist(id).then(res => {
        // console.log(res);
        this.setData({
          songInfo: res.playlist,
          title: res.playlist.name
        })
      })
    } else {
      const res = await getRanking(1)
      // console.log(res);
      this.setData({
        songInfo: res.playlist
      })
    }

  },

  onMusicDetail(e) {
    const id = e.target.dataset.id
    if(id) {
      wx.navigateTo({
        url: '/pages/music-player/music-player?id=' + id
      })
    }
  }

})